/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = wtc_tch.c                                          */
/*  NOTE      =                                                    */
/*  DATE      = 2015/08/26 by songbb                               */
/*******************************************************************/

#include "conntrack.h"

#include "wtc_core.h"
#include "wtc_comm.h"
#include "wtc_tch.h"
#include "wtc_mar.h"

int wtc_read_tch(L7_wtc_packet *p_st_wtc_packet
                , WTC_tch_header *p_st_tch_header)
{
    WTC_PRINT_INFO("wtc_read_tch...\n");
    unsigned int ui_type = 0;
    unsigned int ui_len = 0;
    unsigned int ui_flags = 0;

    if (bytebuff_get_int(p_st_wtc_packet->p_st_packet, 4, &ui_type, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;
    if (bytebuff_get_int(p_st_wtc_packet->p_st_packet, 4, &ui_len, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;
    if (bytebuff_get_int(p_st_wtc_packet->p_st_packet, 4, &ui_flags, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;

    WTC_PRINT_DBG("tmtcm_type:[0x%08x] tcb_type:[%d][%s]\n", ui_type, ui_type >> 16, WTC_TCBTYPE2STR(ui_type >> 16));
    p_st_tch_header->tcb_type = (WTC_tcb_type) (ui_type >> 16);
    p_st_tch_header->len = ui_len;
    p_st_tch_header->flags = ui_flags;

    return FR_SUCC;
error:
    return FR_FAIL;
}


//////////////////////// for analyze direction
int wtc_read_tch_fad(char *p_payload
                    , unsigned int ui_payload_len
                    , unsigned int *p_ui_offset
                    , WTC_tch_header *p_st_tch_header)
{
    WTC_PRINT_INFO("wtc_read_tch_fad...\n");
    unsigned int ui_type = 0;
    unsigned int ui_len = 0;
    unsigned int ui_flags = 0;

    if (wtc_get_int(p_payload, ui_payload_len, p_ui_offset, &ui_type) != FR_SUCC)
        goto error;
    if (wtc_get_int(p_payload, ui_payload_len, p_ui_offset, &ui_len) != FR_SUCC)
        goto error;
    if (wtc_get_int(p_payload, ui_payload_len, p_ui_offset, &ui_flags) != FR_SUCC)
        goto error;

    WTC_PRINT_DBG("tmtcm_type:[0x%08x] tcb_type:[%d][%s]\n", ui_type, ui_type >> 16, WTC_TCBTYPE2STR(ui_type >> 16));
    p_st_tch_header->tcb_type = (WTC_tcb_type) (ui_type >> 16);
    p_st_tch_header->len = ui_len;
    p_st_tch_header->flags = ui_flags;

    return FR_SUCC;
error:
    return FR_FAIL;
}
